package hotel.compare.oversea.controller;

import hotel.base.oversea.entity.MtHotelRoomVo;
import hotel.base.oversea.utils.Result;
import hotel.compare.oversea.service.CompareHotelRoomService;
import hotel.compare.oversea.vo.CompareHotelRoomVo;
import hotel.compare.oversea.vo.GetRoomListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author lmf
 * @Date 2020/5/29 13:52
 * 校验房型控制器
 **/
@Slf4j
@RestController
@RequestMapping("/compareHotelRoom")
@Api(value = "CompareHotelController", tags = {"校验后酒店管理接口"})
public class CompareHotelRoomController {
    @Autowired
    private CompareHotelRoomService compareHotelRoomService;
    /**
     * 开始校验酒店房型信息(暂时不启用)
     * @return
     */
    @GetMapping("/compareHotelRoomBySub")
    @ApiOperation(value = "校验酒店房型信息")
    public Result<Object> compareHotelRoomBySub() {
      return  compareHotelRoomService.compareHotelRoomBySub();
    }


    /**
     * 开始校验酒店房型信息
     * @return
     */
    @GetMapping("/compareHotelRoom")
    @ApiOperation(value = "校验酒店房型信息")
    public Result<Object> compareHotel() {
       /* return  compareHotelRoomService.compareHotelRoom();*/
        return compareHotelRoomService.getCanCreateSubHotel();
       // return compareHotelRoomService.compareHotelBySql();
    }
    /***
     * @Author: lmf
     * @Date: 2020/9/28
     * 2020-09-28 效验房型通过sql效验
     */
    @GetMapping("/compareHotelRoomBySql")
    @ApiOperation(value = "校验酒店房型信息通过sql邮局")
    public Result<Object> compareHotelBySql() {
       // return compareHotelRoomService.compareHotelBySql();
        return compareHotelRoomService.getCanCreateSubHotel();
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/28
     * 2020-09-28 效验房型通过sql效验
     */
    @GetMapping("/compareHotelRoomByHotelIdSql")
    @ApiOperation(value = "校验酒店房型信息通过sql邮局")
    public Result<Object> compareHotelRoomByHotelIdSql(@RequestParam Integer mtHotelId) {
        return compareHotelRoomService.compareHotelRoomByHotelIdSql(mtHotelId);
    }
    /**
     * 获取效验酒店房型列表
     */
    @GetMapping("/compareHotelRoomList")
    @ApiOperation(value = "校验酒店房型信息")
    public Result<Object> compareHotelList() {
        return compareHotelRoomService.getCompareHotelRoomList();
    }

    /**
     * 获取效验后的酒店房型列表
     * 母酒店id+母物理房型id获取对应的美团id
     */
    @PostMapping("/getHotelRoomInfo")
    public Result<MtHotelRoomVo> getCompareHotelInfo(@RequestBody JSONObject jsonObject){
        Integer masterHotelId=jsonObject.getInt("masterHotelId");
        Integer roomId=jsonObject.getInt("roomId");
        log.info("=============请求的参数为{}",roomId);
        Result<MtHotelRoomVo> roomVoResult= compareHotelRoomService.getCompareHotelInfo(masterHotelId,roomId);
        log.info("=========roomVoResult的值为{}====",roomVoResult.toString());
        return roomVoResult;
    }

    /**
     * 初始化数据
     */
    @GetMapping("/init")
    public String initData(){
        compareHotelRoomService.initData();
        return "完成";
    }

    /**
     * @author: lmf
     * @date: 2020/8/13 15:13
     * 房型效验调试
     */
    @GetMapping("adjust")
    public String adjust(){
        compareHotelRoomService.adjust();
        return "adjust";
    }

    /**
     * @author: lmf
     * @date: 2020/9/16 11:27
     * 获取已经匹配的房型列表
     */
    @PostMapping("/getRoomList")
    @ApiOperation(value = "获取已经匹配的房型列表",notes = "必须经过0auth2授权")
    public Result<Object> getRoomList(@RequestBody GetRoomListVO getRoomListVO){
       return compareHotelRoomService.getRoomList(getRoomListVO);
    }

    /**
     * @author: lmf
     * @date: 2020/9/16 14:31
     * 获取携程未匹配的房型列表
     */
    @PostMapping("/getNoCompareRoomList")
    @ApiOperation(value = "获取已经匹配的房型列表",notes = "必须经过0auth2授权")
    public Result<Object> getNoCompareRoomList(@RequestBody GetRoomListVO getRoomListVO){
        return compareHotelRoomService.getNoCompareRoomList(getRoomListVO);
    }

    /**
     * @author: lmf
     * @date: 2020/9/16 15:05
     * 获取美团未匹配的房型列表
     */
    @PostMapping("/getMtNoCompareList")
    @ApiOperation(value = "获取美团未匹配的房型列表",notes = "必须经过0auth2授权")
    public Result<Object> getMtNoCompareList(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        return compareHotelRoomService.getMtNoCompareList(compareHotelRoomVo.getMasterHotelId());
    }

    /**
     * @author: lmf
     * @date: 2020/9/16 20:41
     * 匹配房型入库
     */
    @PostMapping("/matchSuccess")
    @ApiOperation(value = "获取美团未匹配的房型列表",notes = "必须经过0auth2授权")
    public Result<Object> matchSuccess(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        return compareHotelRoomService.matchSuccess(compareHotelRoomVo);
    }


    /**
     * 匹配携程-美团上架的酒店房型相关信息：价格、房态、早餐信息
     */
    @PostMapping("/compareHotelRoomInfoByApi")
    @ApiOperation(value = "根据vo获取对应携程-美团酒店下的房型",notes = "必须经过oauth2授权")
    public Result<Object> compareHotelRoomInfoByApi(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
//        //判断vo是否为空
//        if(ObjectUtils.isEmpty(compareHotelRoomVo)){
//            return new Result<>("参数为空！");
//        }

        return compareHotelRoomService.compareHotelRoomInfoByApi(compareHotelRoomVo);
    }

    /**
     * 匹配携程-美团上架的酒店房型相关信息：价格、房态、早餐信息
     */
    @GetMapping("/compareHotelRoomInfoByApi")
    @ApiOperation(value = "根据所有上架携程-美团酒店下的房型,",notes = "必须经过oauth2授权")
    public Result<Object> compareHotelRoomInfoByAllUpHotel(){
        Result<Object> result = compareHotelRoomService.compareHotelRoomInfoByAllUpHotel();
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/13
     * 定时效验上架酒店房型是否有创建子物理房型数据
    */
    @GetMapping("/checkHotelIsCreateData")
    @ApiOperation(value = "根据所有上架携程-美团酒店下的房型,",notes = "必须经过oauth2授权")
    public Result<Object> checkHotelIsCreateData(){
        Result<Object> result = compareHotelRoomService.checkHotelIsCreateData();
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/20
     * 获取酒店的效验数据
    */
    @PostMapping("/compareRoomList")
    @ApiOperation(value = "获取酒店的效验数据",notes = "必须经过oauth2授权")
    public Result<Object> compareRoomList(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        Result<Object> result = compareHotelRoomService.compareRoomList(compareHotelRoomVo.getMasterHotelId(),compareHotelRoomVo.getMtHotelId());
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/21
     * 人工初步匹配入库
    */
    @PostMapping("/compareSuccess")
    @ApiOperation(value = "人工初步匹配入库",notes = "必须经过oauth2授权")
    public Result<Object> compareSuccess(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        Result<Object> result = compareHotelRoomService.compareSuccess(compareHotelRoomVo);
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/22
     * 最终确认匹配入库并进行创建
    */
    @PostMapping("/finshCompre")
    @ApiOperation(value = "最终确认匹配入库并进行创建",notes = "必须经过oauth2授权")
    public Result<Object> finshCompre(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        Result<Object> result = compareHotelRoomService.finshCompre(compareHotelRoomVo);
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/22
     * 把初步匹配的数据重新进行匹配
    */
    @PostMapping("/recompre")
    @ApiOperation(value = "把初步匹配的数据重新进行匹配",notes = "必须经过oauth2授权")
    public Result<Object> recompre(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        Result<Object> result = compareHotelRoomService.recompre(compareHotelRoomVo);
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/22
     * 提交匹配
    */
    @PostMapping("/commitCompare")
    @ApiOperation(value = "提交匹配",notes = "必须经过oauth2授权")
    public Result<Object> commitCompare(@RequestBody CompareHotelRoomVo compareHotelRoomVo){
        Result<Object> result = compareHotelRoomService.commitCompare(compareHotelRoomVo);
        return result;
    }

    /***
    * @Author: lmf
    * @Date: 2021/1/22 GetRoomListVO getRoomListVO
    */
    @PostMapping("/allCompare")
    @ApiOperation(value = "提交匹配",notes = "必须经过oauth2授权")
    public Result<Object> allCompare(@RequestBody GetRoomListVO getRoomListVO){
        Result<Object> result = compareHotelRoomService.allCompare(getRoomListVO);
        return result;
    }
}
